package org.jeecg.modules.business.repertory.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.business.repertory.entity.WmsRepertoryFreezeHistory;
import org.jeecg.modules.business.repertory.service.IWmsRepertoryFreezeHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 库存-冻结日志
 * @Author: jeecg-boot
 * @Date: 2023-08-01
 * @Version: V1.0
 */
@Api(tags = "库存-冻结日志")
@RestController
@RequestMapping("/repertory/wmsRepertoryFreezeHistory")
@Slf4j
public class WmsRepertoryFreezeHistoryController extends JeecgController<WmsRepertoryFreezeHistory, IWmsRepertoryFreezeHistoryService> {
    @Autowired
    private IWmsRepertoryFreezeHistoryService wmsRepertoryFreezeHistoryService;

    /**
     * 分页列表查询
     *
     * @param wmsRepertoryFreezeHistory
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "库存-冻结日志-分页列表查询")
    @ApiOperation(value = "库存-冻结日志-分页列表查询", notes = "库存-冻结日志-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<WmsRepertoryFreezeHistory>> queryPageList(WmsRepertoryFreezeHistory wmsRepertoryFreezeHistory,
                                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                  HttpServletRequest req) {
        QueryWrapper<WmsRepertoryFreezeHistory> queryWrapper = QueryGenerator.initQueryWrapper(wmsRepertoryFreezeHistory, req.getParameterMap());
        Page<WmsRepertoryFreezeHistory> page = new Page<WmsRepertoryFreezeHistory>(pageNo, pageSize);
        IPage<WmsRepertoryFreezeHistory> pageList = wmsRepertoryFreezeHistoryService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param wmsRepertoryFreezeHistory
     * @return
     */
    @AutoLog(value = "库存-冻结日志-添加")
    @ApiOperation(value = "库存-冻结日志-添加", notes = "库存-冻结日志-添加")
    @RequiresPermissions("repertory:wms_repertory_freeze_history:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody WmsRepertoryFreezeHistory wmsRepertoryFreezeHistory) {
        wmsRepertoryFreezeHistoryService.save(wmsRepertoryFreezeHistory);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param wmsRepertoryFreezeHistory
     * @return
     */
    @AutoLog(value = "库存-冻结日志-编辑")
    @ApiOperation(value = "库存-冻结日志-编辑", notes = "库存-冻结日志-编辑")
    @RequiresPermissions("repertory:wms_repertory_freeze_history:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody WmsRepertoryFreezeHistory wmsRepertoryFreezeHistory) {
        wmsRepertoryFreezeHistoryService.updateById(wmsRepertoryFreezeHistory);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "库存-冻结日志-通过id删除")
    @ApiOperation(value = "库存-冻结日志-通过id删除", notes = "库存-冻结日志-通过id删除")
    @RequiresPermissions("repertory:wms_repertory_freeze_history:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        wmsRepertoryFreezeHistoryService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "库存-冻结日志-批量删除")
    @ApiOperation(value = "库存-冻结日志-批量删除", notes = "库存-冻结日志-批量删除")
    @RequiresPermissions("repertory:wms_repertory_freeze_history:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.wmsRepertoryFreezeHistoryService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "库存-冻结日志-通过id查询")
    @ApiOperation(value = "库存-冻结日志-通过id查询", notes = "库存-冻结日志-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<WmsRepertoryFreezeHistory> queryById(@RequestParam(name = "id", required = true) String id) {
        WmsRepertoryFreezeHistory wmsRepertoryFreezeHistory = wmsRepertoryFreezeHistoryService.getById(id);
        if (wmsRepertoryFreezeHistory == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(wmsRepertoryFreezeHistory);
    }

    /**
     * 通过id查询
     *
     * @param repertoryId
     * @return
     */
    //@AutoLog(value = "库存-冻结日志-通过id查询")
    @ApiOperation(value = "库存-冻结日志-通过库存记录id查询", notes = "库存-冻结日志-通过库存记录id查询")
    @GetMapping(value = "/queryByRepertoryId")
    public Result<List<WmsRepertoryFreezeHistory>> queryByRepertoryId(@RequestParam(name = "repertoryId", required = true) String repertoryId) {
        List<WmsRepertoryFreezeHistory> wmsRepertoryFreezeHistoryList = wmsRepertoryFreezeHistoryService.list(new LambdaQueryWrapper<WmsRepertoryFreezeHistory>()
                .eq(WmsRepertoryFreezeHistory::getWmsRepertoryId, repertoryId)
                .orderByDesc(WmsRepertoryFreezeHistory::getCreateTime));
        return Result.OK(wmsRepertoryFreezeHistoryList);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param wmsRepertoryFreezeHistory
     */
    @RequiresPermissions("repertory:wms_repertory_freeze_history:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, WmsRepertoryFreezeHistory wmsRepertoryFreezeHistory) {
        return super.exportXls(request, wmsRepertoryFreezeHistory, WmsRepertoryFreezeHistory.class, "库存-冻结日志");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequiresPermissions("repertory:wms_repertory_freeze_history:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, WmsRepertoryFreezeHistory.class);
    }

}
